#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void Swap(long long* a, long long* b)
{
	long long tmp = 0;
	tmp = *a;
	*a = *b;
	*b = tmp;
}
int main()
{
	long long n;
	long long sum;
	scanf("%ld", &n);
	long long a[n];
	int i = 0;
	for (i = 0;i < n;i++)
	{
		scanf("%ld", &a[i]);
	}
	for (i = 0;i < 2;i++)
	{
		int j = 0;
		for (j = 0;j <n-1;j++)
		{
			if (a[j] > a[j + 1])
			{
				Swap(&a[j], &a[j + 1]);
			}
		}
	}
	sum = a[n - 1] + a[n - 2];
	printf("%ld", sum);
	return 0;
}